/*
 *
 * Created on: 22.09.2012
 *
 * exception.h
 * This file is part of KOBUS
 * 
 * Copyright (C) 2012 - Ivan Penkin, MIPT
 * grek.penkin@gmail.com
 *
 * KOBUS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * KOBUS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KOBUS; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 *  
 */

#ifndef EXCEPTION_H_
#define EXCEPTION_H_

#include <KobusCommon_global.h>

#include <qobject.h>
#include <qstring.h>

#include <log.h>

namespace kobus
{

class KOBUS_COMMON_EXPORT Exception: public QObject
{
    Q_OBJECT

    Q_PROPERTY(int errcode READ errcode WRITE setErrcode)
    Q_PROPERTY(const QString & message READ message WRITE setMessage)

  public:
    Exception(const int /* errno */, QObject * parent = 0);
    Exception(const int /* err */, const QString &, QObject * parent = 0);

    Exception(const Exception &);
    Exception(Exception &);

    virtual
    ~Exception() throw () {};

    Exception & operator=(const Exception &);


    static const int NO_ERRNO = 0;

    int             errcode() const;
    const QString & message() const;

    void setErrcode(const int err);
    void setMessage(const QString & /* message */);

  protected:
    void log() const;

    Log     d_log;
    int     d_errno;
    QString d_message;

  private:
    explicit
    Exception(QObject * parent = 0);
};

}  /* namespace kobus */

Q_DECLARE_TYPEINFO(kobus::Exception, Q_COMPLEX_TYPE);

#endif /* EXCEPTION_H_ */
